package com.lichen.remind.adapter;

import java.util.Locale;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.lichen.remind.R;
import com.lichen.remind.fragment.AboutMeFragment;
import com.lichen.remind.fragment.TabFragment;

public class FragmentAdapter extends FragmentPagerAdapter {

	private Context mContext;

	public FragmentAdapter(Context context, FragmentManager fm) {
		super(fm);
		mContext = context;
	}

	@Override
	public Fragment getItem(int position) {
		Fragment fragment;
		if (position == 2) {
			fragment = new AboutMeFragment();
		} else {
			fragment = new TabFragment();
			Bundle args = new Bundle();
			args.putInt(TabFragment.TAB_POSITION, position + 1);
			fragment.setArguments(args);
		}
		return fragment;
	}

	@Override
	public int getCount() {
		return 3;
	}

	@Override
	public CharSequence getPageTitle(int position) {
		if (position == 2) {
			return mContext.getString(R.string.about_me_title);
		} else {
			Locale l = Locale.getDefault();
			return mContext.getString(R.string.tab_fragment_title, position + 1).toUpperCase(l);
		}
	}
}
